<?php /*a:1:{s:101:"E:\hisiphp_cms_1.0\the-first-project---wxcms\thinkphp5.1\tp5\application\admin\view\article\edit.html";i:1616744947;}*/ ?>
<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>

                    <div class="layui-input-block">
                        <input type="text" name="title" value="<?php echo htmlentities($article['title']); ?>" required  lay-verify="required" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                        <div class="layui-inline layui-word-aux">新闻标题不能超过30个字哦</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">作者</label>
                    <div class="layui-input-inline">
                        <input type="text" required value="<?php echo htmlentities($article['author']); ?>" lay-verify="required" disabled placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
                        <input type="hidden" value="<?php echo htmlentities($article['user_id']); ?>" name="user_id">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">新闻简介</label>

                    <div class="layui-input-block">
                        <input type="text"  name="content" value="<?php echo htmlentities($article['content']); ?>" required  lay-verify="required" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                        <div class="layui-inline layui-word-aux">新闻简介不能超过78个字哦</div>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">请选择一个音乐</label>
                    <div class="layui-input-inline">
                        <select name="music_id" lay-verify="required" lay-search>

                            <?php foreach($music as $value): if(($value['id'] == $article['user_id'])): ?>
                                <option value="<?php echo htmlentities($value['id']); ?>"><?php echo htmlentities($value['title']); ?></option>
                                <?php endif; ?>
                            <?php endforeach; ?>
                            <option value="0">请选择</option>
                            <?php foreach($music as $v): if(($v['id'] != $article['user_id'])): ?>
                                <option value="<?php echo htmlentities($v['id']); ?>"><?php echo htmlentities($v['title']); ?></option>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>
                <input type="hidden" id="__token__" name="__token__" value="<?php echo htmlentities(app('request')->token()); ?>" />
                <div class="layui-form-item">
                    <label class="layui-form-label">头像图片</label>
                    <button type="button" class="layui-btn" id="avatarImgSrc">
                        <i class="layui-icon"></i>上传图片
                    </button>
                    <input class="layui-upload-file" type="file" accept="" name="file">
                    <div class="layui-inline layui-word-aux">封面图片：（超过 80*80 图片将被缩小,图片不得超过2M）</div>
                    <img src="<?php echo htmlentities($imageUrl); ?><?php echo htmlentities($article['avatar']); ?>" alt="" id="avatarShow" style="">
                    <input type="hidden" value="<?php echo htmlentities($article['avatar']); ?>" id="avatar" name="avatar" >
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">文章图片</label>
                    <button type="button" class="layui-btn" id="articleImgSrc">
                        <i class="layui-icon"></i>上传图片
                    </button>
                    <input class="layui-upload-file" type="file" accept="" name="file">
                    <div class="layui-inline layui-word-aux">封面图片：（超过 400*220 图片将被缩小,图片不得超过2M）</div>
                    <img src="<?php echo htmlentities($imageUrl); ?><?php echo htmlentities($article['imgSrc']); ?>" alt="" id="articleShow" style="">
                    <input type="hidden" value="<?php echo htmlentities($article['imgSrc']); ?>" id="imgSrc" name="imgSrc">
                </div>


                <div class="layui-form-item">
                    <label for="detail" class="layui-form-label" style="width: 150px;margin-top:10px;">新闻正文：</label>
                    <div class="layui-input-inline" style="margin-top:10px;width: 695px;">
                        <textarea id="detail" name="detail" style="display: none;"><?php echo htmlentities($article['detail']); ?></textarea>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                        <i class="layui-icon layui-icon-ok"></i>
                        提交
                    </button>
                    <button type="reset" class="pear-btn pear-btn-sm">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </div>
    </div>

</form>
<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['form','jquery','layedit','upload','layer'],function(){
        let form = layui.form;
        let $ = layui.jquery;
        let layedit = layui.layedit;
        let upload = layui.upload;
        let layer = layui.layer;

        layedit.build('detail');//建立编辑器

        //头像图片上传
        upload.render({
            elem: '#avatarImgSrc', //绑定元素,
            url: '<?php echo url("admin/article/uploadAvatarImage"); ?>', //上传接口
            done: function(res){
                if (res.code === 1) {
                    $("#avatar").val(res.data);
                    $("#avatarShow").prop("src", "<?php echo htmlentities($imageUrl); ?>" + res.data);
                    $("#avatarShow").prop("style", "width: 80px;height: 80px;");
                } else {
                    layer.open({
                        title : res.msg,
                        content : res.data
                    })
                }
            },
            error: function(){
                //请求异常回调
            }
        });
        //新闻图片上传
        upload.render({
            elem: '#articleImgSrc', //绑定元素,
            url: '<?php echo url("admin/article/uploadArticleImage"); ?>', //上传接口
            done: function(res){
                if (res.code === 1) {
                    $("#imgSrc").val(res.data);
                    $("#articleShow").prop("src", "<?php echo htmlentities($imageUrl); ?>" + res.data);
                    $("#articleShow").prop("style", "width: 220px;height: 180px;");
                } else {
                    layer.open({
                        title : res.msg,
                        content : res.data
                    })
                    $("#__token__").val(res.token);
                }
            },
            error: function(){
                //请求异常回调
            }
        });
        /**
         * 保存
         */
        form.on('submit(user-save)', function(data){
            data.field.detail = "<b>abc error</b>";
            data.field.id = "<?php echo htmlentities($article['id']); ?>";
            $.ajax({
                url:'<?php echo url("admin/article/editArticle"); ?>',
                data:JSON.stringify(data.field),
                dataType:'json',
                contentType:'application/json',
                type:'post',
                success:function(result){
                    if(result.code === 1){
                        layer.msg(result.msg,{icon:1,time:1000},function(){
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        });
                    }else{
                        $("#__token__").val(result.token);
                        layer.msg(result.data,{icon:2,time:1000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>